package com.example.stock.service.impl;

import com.alibaba.fastjson.JSON;
import com.example.stock.service.IServiceTushare;
import com.example.stock.vo.TushareReqVo;
import com.example.stock.vo.TushareRspVo;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class ServiceTushareImpl implements IServiceTushare {

    private RestTemplate restTemplate;

    public ServiceTushareImpl(RestTemplateBuilder restTemplateBuilder) {
        this.restTemplate = restTemplateBuilder.rootUri("http://api.waditu.com").build();
    }

    public TushareRspVo someRestCall() {
        String json = "{\n" +
                "  \"api_name\": \"stock_basic\",\n" +
                "  \"token\": \"09640b7c249de22f51c81fa10ebadcc2c31924864746e333e5ffbe2c\",\n" +
                "  \"params\": {\n" +
                "    \"list_status\": \"L\"\n" +
                "  },\n" +
                "  \"fields\": \"\"\n" +
                "}";
        return this.restTemplate.postForObject("/", JSON.parseObject(json, TushareReqVo.class), TushareRspVo.class);
    }

}